<template>
    <div class="common-layout">
        <el-container>
            <el-header style="height: 200px;margin-bottom: 100px;">
                <table>
                    <tr>
                        <td>
                            <el-upload class="avatar-uploader"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" :show-file-list="false"
                                :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                                <img v-if="Traceabilities.phtoto" :src="Traceabilities.phtoto" class="avatar" />
                                <el-icon v-else class="avatar-uploader-icon">
                                    <Plus />
                                </el-icon>
                            </el-upload>
                        </td>
                        <td>

                            <h2>{{ Traceabilities.goodsName }}</h2>

                            <span>生产批次：{{ Traceabilities.produce }}</span>
                            <span>保质期：{{ Traceabilities.safetyDay }}天</span><br />
                            <span>生产许可证号：{{ Traceabilities.licenseNumber }}</span>
                            <span>生产企业：{{ Traceabilities.enterprise }}</span>
                            <h3>商品检验报告</h3>

                            <el-upload v-model:file-list="fileList"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" list-type="picture-card"
                                :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </el-upload>

                            <el-dialog v-model="dialogVisible">
                                <img w-full :src="dialogImageUrl" alt="Preview Image" />
                            </el-dialog>
                        </td>

                    </tr>

                </table>
            </el-header>
            <el-main>
                <el-tabs type="border-card">
                    <el-tab-pane label="养殖信息">
                        <div style="margin-bottom: 10px;">
                            <span style="color:dodgerblue;"> 养殖信息</span> <el-button
                                @click="dialogFormVisible = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formInline" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="品种:">
                                    {{ formInline.variety }}
                                </el-form-item>
                                <el-form-item label="来源：">
                                    {{ formInline.source }}
                                </el-form-item>
                                <el-form-item label="饲养天数：">
                                    {{ formInline.feedingDay }}
                                </el-form-item>
                                <el-form-item label="饲养品牌：">
                                    {{ formInline.feedingBrand }}
                                </el-form-item>
                                <el-form-item label="饲养负责人：">
                                    {{ formInline.feedingPerson }}
                                </el-form-item>
                                <el-form-item label="出栏日期：">
                                    {{ formInline.endDate.substring(0, 10) }}
                                </el-form-item>
                            </el-form>
                            <el-dialog v-model="dialogFormVisible" title="养殖信息" width="500">
                                <el-form :model="form" label-width="140px">
                                    <el-form-item label="品种">
                                        <el-input v-model="form.variety" />
                                    </el-form-item>
                                    <el-form-item label="来源">
                                        <el-input v-model="form.source" />
                                    </el-form-item>
                                    <el-form-item label="饲养天数">
                                        <el-input v-model="form.feedingDay" />
                                    </el-form-item>
                                    <el-form-item label="饲养品牌">
                                        <el-input v-model="form.feedingBrand" />
                                    </el-form-item>
                                    <el-form-item label="饲养负责人">
                                        <el-input v-model="form.feedingPerson" />
                                    </el-form-item>
                                    <el-form-item label="出栏日期">
                                        <el-input v-model="form.endDate" type="date" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveCultivation">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                        <div style="margin-bottom: 10px;">
                            <span style="color:dodgerblue;">保健信息</span>
                            <el-button @click="dialogFormVisible1 = true">新增行</el-button>
                            <el-divider />
                            <el-table :data="tableData" border style="width: 100%">
                                <el-table-column prop="date" label="饲养天数">
                                    <template #default="row">
                                        <el-input v-model="row.data" style="width: 120px" />
                                    </template>
                                </el-table-column>
                                <el-table-column prop="name" label="保健方式">
                                    <template #default="row">
                                        <el-input v-model="row.name" style="width: 120px" />
                                    </template>
                                </el-table-column>
                                <el-table-column prop="address" label="保健方法">
                                    <template #default="row">
                                        <el-input v-model="row.address" style="width: 120px" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作" />
                            </el-table>
                        </div>
                        <div style="margin-bottom: 15px;" >
                            <span style="color:dodgerblue;"> 动检证</span>
                            <el-divider />
                            <el-upload v-model:file-list="fileList1"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" list-type="picture-card"
                                :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </el-upload>

                            <el-dialog v-model="dialogVisible">
                                <img w-full :src="dialogImageUrl" alt="Preview Image" />
                            </el-dialog>
                        </div>
                        <div>
                            <span style="color:dodgerblue;">企业信息</span> <el-button
                                @click="dialogFormVisible1 = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formEnterprise" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="养殖场:">
                                    {{ formEnterprise.cultivationAddress }}
                                </el-form-item>
                                <el-form-item label="负责人：">
                                    {{ formEnterprise.person }}
                                </el-form-item>
                                <el-form-item label="存栏数量：">
                                    {{ formEnterprise.herdsNumber }}只
                                </el-form-item>
                            </el-form>
                            <span style="color:dodgerblue;">企业照片</span>
                            <el-divider />
                            <el-upload v-model:file-list="fileList2"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" list-type="picture-card"
                                :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </el-upload>

                            <el-dialog v-model="dialogVisible">
                                <img w-full :src="dialogImageUrl" alt="Preview Image" />
                            </el-dialog>

                            <el-dialog v-model="dialogFormVisible1" title="企业信息" width="500">
                                <el-form :model="formEnterprise" label-width="140px">
                                    <el-form-item label="养殖场">
                                        <el-input v-model="formEnterprise.cultivationAddress" />
                                    </el-form-item>
                                    <el-form-item label="负责人">
                                        <el-input v-model="formEnterprise.person" />
                                    </el-form-item>
                                    <el-form-item label="存栏数量">
                                        <el-input v-model="formEnterprise.herdsNumber" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveEnterprise">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="屠宰信息">
                        <div style="margin-bottom: 10px;">
                            <span style="color:dodgerblue;"> 屠宰信息</span> <el-button
                                @click="dialogFormVisible = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formSlaughter" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="批次:">
                                    {{ formSlaughter.produce }}
                                </el-form-item>
                                <el-form-item label="到厂均重：">
                                    {{ formSlaughter.weight }}
                                </el-form-item>
                                <el-form-item label="到厂时间：">
                                    {{ formSlaughter.arriveTime.substring(0, 19).replace("T", " ") }}
                                </el-form-item>
                                <el-form-item label="屠宰时间：">
                                    {{ formSlaughter.slaughterTime.substring(0, 19).replace("T", " ") }}
                                </el-form-item>


                            </el-form>
                            <el-dialog v-model="dialogFormVisible3" title="屠宰信息" width="500">
                                <el-form :model="formSlaughters" label-width="140px">
                                    <el-form-item label="批次">
                                        <el-input v-model="formSlaughters.produce" />
                                    </el-form-item>
                                    <el-form-item label="到厂均重">
                                        <el-input v-model="formSlaughters.weight" />
                                    </el-form-item>
                                    <el-form-item label="到厂时间">
                                        <el-input v-model="formSlaughters.arriveTime" type="date" />
                                    </el-form-item>
                                    <el-form-item label="屠宰时间">
                                        <el-input v-model="formSlaughters.slaughterTime" type="date" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveSlaughter">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                        <div>
                            <span style="color:dodgerblue;">企业信息</span> <el-button
                                @click="dialogFormVisible10 = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formEnterprise" style="width: 550px;margin-top: 15px;">
                                <el-form-item label="公司名称:">
                                    {{ formSEnterprises.enterpriseName }}
                                </el-form-item>
                                <el-form-item label="成立时间:">
                                    {{ formSEnterprises.createTime }}
                                </el-form-item>
                                <el-form-item label="公司地址:">
                                    {{ formSEnterprises.enterpriseAddress }}
                                </el-form-item>
                                <el-form-item label="公司简介:">
                                    {{ formSEnterprises.enterpriseDesc }}
                                </el-form-item>
                            </el-form>
                            <span style="color:dodgerblue;">企业照片</span>
                            <el-divider />
                            <el-upload class="avatar-uploader"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" :show-file-list="false"
                                :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                                <img v-if="formEnterprise.ePhoto" :src="formEnterprise.ePhoto" class="avatar" />
                                <el-icon v-else class="avatar-uploader-icon">
                                    <Plus />
                                </el-icon>
                            </el-upload>

                            <el-dialog v-model="dialogFormVisible10" title="企业信息" width="700">
                                <el-form :model="formEnterprise" label-width="140px">
                                    <el-form-item label="公司名称">
                                        <el-input v-model="formSEnterprise.enterpriseName" />
                                    </el-form-item>
                                    <el-form-item label="公司地址">
                                        <el-select v-model="formSEnterprise.provinces" placeholder="请选择" size="large"
                                            style="width: 150px" @change="GetCities">
                                            <el-option v-for="item in Privinces" :key="item.provinceId"
                                                :label="item.province" :value="item.provinceId" />
                                        </el-select>
                                        <el-select v-model="formSEnterprise.cities" placeholder="请选择" size="large"
                                            style="width: 150px" @change="GetAreas">
                                            <el-option v-for="item in Cities" :key="item.cityId" :label="item.city"
                                                :value="item.cityId" />
                                        </el-select>
                                        <el-select v-model="formSEnterprise.areas" placeholder="请选择" size="large"
                                            style="width: 150px">
                                            <el-option v-for="item in Areas" :key="item.areaId" :label="item.area"
                                                :value="item.areaId" />
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="成立时间">
                                        <el-input v-model="formSEnterprise.createTime" type="date" />
                                    </el-form-item>
                                    <el-form-item label="公司简介">
                                        <el-input v-model="formSEnterprise.enterpriseDesc" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveSEnterprise">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="深加工">
                        <!-- 深加工 -->
                        <div>
                            <span style="color:dodgerblue;"> 深加工信息</span> <el-button
                                @click="dialogFormVisible4 = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formProcessingr" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="班组:">
                                    {{ formProcessingr.team }}
                                </el-form-item>
                                <el-form-item label="负责人：">
                                    {{ formProcessingr.person }}
                                </el-form-item>

                            </el-form>
                            <el-dialog v-model="dialogFormVisible4" title="深加工信息" width="500">
                                <el-form :model="formProcessingrs" label-width="140px">
                                    <el-form-item label="班组">
                                        <el-input v-model="formProcessingrs.team" />
                                    </el-form-item>
                                    <el-form-item label="负责人">
                                        <el-input v-model="formProcessingrs.person" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveProcessingr">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                        <!-- 供货商 -->
                        <div>
                            <h3><span style="color:dodgerblue;">供应商信息</span></h3>
                            <el-divider />
                            <span>原料</span><el-button @click="dialogFormVisible5 = true">设置</el-button>
                            <el-form :inline="true" :model="formrawmaterial" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="生产批次:">

                                    {{ formrawmaterials.rawMaterialProduce }}
                                </el-form-item>
                            </el-form>
                            <el-dialog v-model="dialogFormVisible5" title="原料信息" width="500">
                                <el-form :model="formEnterprise" label-width="140px">
                                    <el-form-item label="生产批次">
                                        <el-input v-model="formrawmaterial.rawMaterialProduce" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveRawMaterial">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                            <span>辅料</span><el-button @click="dialogFormVisible6 = true">设置</el-button>
                            <el-form :inline="true" :model="formAccessoriess" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="生产批次:">

                                    {{ formAccessoriess.accessoriesProduce }}
                                </el-form-item>
                            </el-form>
                            <el-dialog v-model="dialogFormVisible6" title="辅料信息" width="500">
                                <el-form :model="formAccessories" label-width="140px">
                                    <el-form-item label="生产批次">
                                        <el-input v-model="formAccessories.accessoriesProduce" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveAccessories">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                            <span>添加剂</span><el-button @click="dialogFormVisible7 = true">设置</el-button>
                            <el-form :inline="true" :model="formAdditives" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="生产批次:">

                                    {{ formAdditives.additiveProduce }}
                                </el-form-item>
                            </el-form>
                            <el-dialog v-model="dialogFormVisible7" title="添加剂信息" width="500">
                                <el-form :model="formEnterprise" label-width="140px">
                                    <el-form-item label="生产批次">
                                        <el-input v-model="formAdditive.additiveProduce" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SaveAdditive">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                            <span>包材</span><el-button @click="dialogFormVisible8 = true">设置</el-button>
                            <el-form :inline="true" :model="formAdditive" style="width: 350px;margin-top: 15px;">
                                <el-form-item label="生产批次:">

                                    {{ formPackagings.packagingMaterialsProduce }}
                                </el-form-item>
                            </el-form>
                            <el-dialog v-model="dialogFormVisible8" title="包材信息" width="500">
                                <el-form :model="formEnterprise" label-width="140px">
                                    <el-form-item label="生产批次">
                                        <el-input v-model="formPackaging.packagingMaterialsProduce" />
                                    </el-form-item>
                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SavePackaging">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                        <!-- 企业 -->
                        <div style=" margin-top: 15px;">
                            <span style="color:dodgerblue;">企业信息</span> <el-button
                                @click="dialogFormVisible9 = true">设置</el-button>
                            <el-divider />
                            <el-form :inline="true" :model="formpEnterprise" style="width: 750px;margin-top: 15px;">
                                <el-form-item label="公司名称:">
                                    {{ formpEnterprise.firmName }}
                                </el-form-item>
                                <el-form-item label="生产许可证号：">
                                    {{ formpEnterprise.licenseNumber }}
                                </el-form-item>
                            </el-form>
                            <span style="color:dodgerblue;">企业照片</span>
                            <el-divider />
                            <el-upload class="avatar-uploader"
                                action="https://localhost:44301/api/AdminStystem/uploadFile" :show-file-list="false"
                                :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                                <img v-if="formpEnterprise.ePhoto" :src="formpEnterprise.ePhoto" class="avatar" />
                                <el-icon v-else class="avatar-uploader-icon">
                                    <Plus />
                                </el-icon>
                            </el-upload>

                            <el-dialog v-model="dialogFormVisible9" title="企业信息" width="500">
                                <el-form :model="formPEnterprise" label-width="140px">
                                    <el-form-item label="公司名称">
                                        <el-input v-model="formPEnterprise.firmName" />
                                    </el-form-item>
                                    <el-form-item label="生产许可证号">
                                        <el-input v-model="formPEnterprise.licenseNumber" />
                                    </el-form-item>

                                </el-form>
                                <template #footer>
                                    <div class="dialog-footer">
                                        <el-button type="primary" @click="SavePEnterprise">
                                            保存
                                        </el-button>
                                    </div>
                                </template>
                            </el-dialog>
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </div>
</template>



<script lang="ts" setup>
import axios from 'axios'
import { ElMessage } from 'element-plus'
import { onMounted, reactive, ref } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import type { UploadProps, UploadUserFile } from 'element-plus'
import { useRouter } from 'vue-router'
const userouter = useRouter()

const fileList = ref<UploadUserFile[]>([])
const fileList1 = ref<UploadUserFile[]>([])
const fileList2 = ref<UploadUserFile[]>([])
const dialogImageUrl = ref('')
const dialogVisible = ref(false)

const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
    console.log(uploadFile, uploadFiles)
}

const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
    dialogImageUrl.value = uploadFile.url!
    dialogVisible.value = true
}


//#region 商品信息
const Traceabilities = reactive({
    traceabilityId: 0,
    goodsId: userouter.currentRoute.value.query.id,
    produce: "",
    safetyDay: 0,
    licenseNumber: "",
    enterprise: "",
    informationComp: "",
    phtoto: "",
    goodsName: ""
})
const GetTraceabilities = () => {
    axios.get('https://localhost:44301/api/AdminStystem/Gettraceability', {
        params: {
            id: userouter.currentRoute.value.query.id
        }
    }).then(res => {
        console.log(res.data.data)
        Traceabilities.produce = res.data.data[0].produce
        Traceabilities.safetyDay = res.data.data[0].safetyDay
        Traceabilities.licenseNumber = res.data.data[0].licenseNumber
        Traceabilities.enterprise = res.data.data[0].enterprise
        Traceabilities.phtoto = res.data.data[0].phtoto
        Traceabilities.goodsName = res.data.data[0].goodsName
    })
}
//#endregion

//#region 养殖信息
const formInline = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    variety: "",
    source: "",
    feedingDay: 0,
    feedingBrand: "",
    feedingPerson: "",
    endDate: ""
})

const getCultivation = () => {
    axios.get('https://localhost:44301/api/Cultivation/GetCultivations', {
        params: {
            id: formInline.goodsId
        }
    }).then(res => {

        formInline.variety = res.data.data.variety
        formInline.source = res.data.data.source
        formInline.feedingDay = res.data.data.feedingDay
        formInline.feedingBrand = res.data.data.feedingBrand
        formInline.feedingPerson = res.data.data.feedingPerson
        formInline.endDate = res.data.data.endDate
    })
}
const form = reactive({
    goodsId: 1,
    variety: "",
    source: "",
    feedingDay: 0,
    feedingBrand: "",
    feedingPerson: "",
    endDate: ""
})
const dialogFormVisible = ref(false)
const SaveCultivation = () => {
    axios.post('https://localhost:44301/api/Cultivation/AddCultivation', form).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
//#endregion

//#region 保健信息
const tableData = [
    {
        date: '2016-05-03',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-02',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },
    {
        date: '2016-05-04',
        name: 'Tom',
        address: 'No. 189, Grove St, Los Angeles',
    },

]
//#endregion

//#region 企业信息
const formEnterprise = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    cultivationAddress: "",
    person: "",
    herdsNumber: null,
    ePhoto: ""
})

const handleAvatarSuccess: UploadProps['onSuccess'] = (
    response,
    uploadFile
) => {
    formEnterprise.ePhoto = 'https://localhost:44301' + response
}

const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
    if (rawFile.type !== 'image/jpeg') {
        ElMessage.error('封面照必须是jpg!')
        return false
    } else if (rawFile.size / 1024 / 1024 > 2) {
        ElMessage.error('封面照大小不能超过 2MB!')
        return false
    }
    return true
}
const dialogFormVisible1 = ref(false)
const SaveEnterprise = () => {
    formEnterprise.cultivationAddress = "";
    formEnterprise.person = "";
    formEnterprise.herdsNumber = null;
    axios.post('https://localhost:44301/api/Cultivation/AddEnterprise', formEnterprise).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible1.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const getEnterprise = () => {
    axios.get('https://localhost:44301/api/Cultivation/GetEnterprise', {
        params: {
            id: formInline.goodsId
        }
    }).then(res => {

        formEnterprise.cultivationAddress = res.data.data.cultivationAddress
        formEnterprise.person = res.data.data.person
        formEnterprise.herdsNumber = res.data.data.herdsNumber
        formEnterprise.ePhoto = res.data.data.ePhoto
    })
}
//#endregion

//#region 屠宰信息
const formSlaughter = reactive({
    goodsId: 1,
    produce: "",
    weight: 0,
    arriveTime: "",
    slaughterTime: ""
})

const getSlaughter = () => {
    axios.get('https://localhost:44301/api/Slaughter/GetSlaughters', {
        params: {
            id: formInline.goodsId
        }
    }).then(res => {
        console.log(res.data.data)
        formSlaughter.produce = res.data.data.produce
        formSlaughter.weight = res.data.data.weight
        formSlaughter.arriveTime = res.data.data.arriveTime
        formSlaughter.slaughterTime = res.data.data.slaughterTime

    })
}
const formSlaughters = reactive({
    goodsId: 1,
    produce: "",
    weight: 0,
    arriveTime: "",
    slaughterTime: ""
})
const dialogFormVisible3 = ref(false)
const SaveSlaughter = () => {
    axios.post('https://localhost:44301/api/Slaughter/AddSlaughter', form).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
//#endregion

//#region 屠宰企业信息
const formSEnterprise = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    enterpriseName: "",
    enterpriseAddress: "",
    createTime: "",
    enterpriseDesc: "",
    provinces: "",
    cities: "",
    areas: ""
})
const SaveSEnterprise = () => {
    formSEnterprise.enterpriseAddress = formSEnterprise.provinces + formSEnterprise.cities + formSEnterprise.areas
    axios.post("https://localhost:44301/api/Slaughter/AddSEnterprise", formSEnterprise).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible10.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const dialogFormVisible10 = ref(false)
const formSEnterprises = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    enterpriseName: "",
    enterpriseAddress: "",
    createTime: "",
    enterpriseDesc: "",

})
const getSEnterprises = () => {
    axios.get('https://localhost:44301/api/Slaughter/GetSEnterprise', {
        params: {
            id: formSEnterprises.goodsId
        }
    }).then(res => {

        formSEnterprises.enterpriseName = res.data.data.enterpriseName
        formSEnterprises.enterpriseAddress = res.data.data.enterpriseAddress
        formSEnterprises.createTime = res.data.data.createTime
        formSEnterprises.enterpriseDesc = res.data.data.enterpriseDesc
    })
}
const Privinces = ref([])
const labels = reactive({
    ProvinceId: "",
    cityId: ""
})
const GetPrivinces = () => {
    axios.get("https://localhost:44301/api/Cultivation/GetProvinces").then(res => {
        Privinces.value = res.data.data


    })
}
const Cities = ref([])
const GetCities = () => {

    axios.get("https://localhost:44301/api/Cultivation/GetCities?ProvinceId=" + formSEnterprise.provinces
    ).then(res => {
        console.log(res.data.data)
        Cities.value = res.data.data

    })
}
const Areas = ref([])
const GetAreas = () => {

    axios.get("https://localhost:44301/api/Cultivation/GetAreas?CityId=" + formSEnterprise.cities
    ).then(res => {
        console.log(res.data.data)
        Areas.value = res.data.data
    })
}
//#endregion

//#region 深加工信息
const formProcessingr = reactive({
    goodsId: 1,
    team: "",
    person: ""
})

const getProcessingr = () => {
    axios.get('https://localhost:44301/api/Processingr/GetProcessingr', {
        params: {
            id: formInline.goodsId
        }
    }).then(res => {

        formProcessingr.team = res.data.data.team
        formProcessingr.person = res.data.data.person
        console.log(res.data.data.team)
    })
}
const formProcessingrs = reactive({
    goodsId: 1,
    team: "",
    person: ""
})
const dialogFormVisible4 = ref(false)
const SaveProcessingr = () => {
    axios.post('https://localhost:44301/api/Processingr/AddProcessingr', form).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible4.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
//#endregion

//#region 供货商信息
//原料
const formrawmaterial = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    rawMaterialProduce: ""
})
const dialogFormVisible5 = ref(false)
const SaveRawMaterial = () => {
    axios.post('https://localhost:44301/api/Processingr/AddrawMaterial', formrawmaterial).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible5.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const formrawmaterials = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    rawMaterialProduce: ""
})
const getRawMaterial = () => {
    axios.get('https://localhost:44301/api/Processingr/GetRawMaterial', {
        params: {
            id: formrawmaterial.goodsId
        }
    }).then(res => {
        formrawmaterials.rawMaterialProduce = res.data.data.rawMaterialProduce
    })
}
//辅料
const formAccessories = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    accessoriesProduce: ""
})
const dialogFormVisible6 = ref(false)
const SaveAccessories = () => {
    axios.post('https://localhost:44301/api/Processingr/AddAccessories', formAccessories).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible3.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const formAccessoriess = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    accessoriesProduce: ""
})
const getAccessories = () => {
    axios.get('https://localhost:44301/api/Processingr/GetAccessories', {
        params: {
            id: formAccessories.goodsId
        }
    }).then(res => {
        formAccessoriess.accessoriesProduce = res.data.data.accessoriesProduce
    })
}
//添加剂
const formAdditive = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    additiveProduce: ""
})
const dialogFormVisible7 = ref(false)
const SaveAdditive = () => {
    axios.post('https://localhost:44301/api/Processingr/AddAdditive', formAdditive).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible4.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const formAdditives = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    additiveProduce: ""
})
const getAdditive = () => {
    axios.get('https://localhost:44301/api/Processingr/GetAdditive', {
        params: {
            id: formAdditive.goodsId
        }
    }).then(res => {
        formAdditives.additiveProduce = res.data.data.additiveProduce
    })
}
//包材
const formPackaging = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    packagingMaterialsProduce: ""
})
const dialogFormVisible8 = ref(false)
const SavePackaging = () => {
    axios.post('https://localhost:44301/api/Processingr/AddPackagingMaterials', formPackaging).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible5.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const formPackagings = reactive({
    goodsId: userouter.currentRoute.value.query.id,
    packagingMaterialsProduce: ""
})
const getPackaging = () => {
    axios.get('https://localhost:44301/api/Processingr/GetPackagingMaterials', {
        params: {
            id: formPackaging.goodsId
        }
    }).then(res => {
        formPackagings.packagingMaterialsProduce = res.data.data.packagingMaterialsProduce
    })
}

//#endregion

//#region 深加工企业信息
const formPEnterprise = reactive({
    goodsId: 1,
    firmName: "",
    licenseNumber: "",
    ePhoto: ""
})

const dialogFormVisible9 = ref(false)
const SavePEnterprise = () => {

    axios.post('https://localhost:44301/api/Processingr/AddPEnterprise', formPEnterprise).then(res => {
        if (res.data.statusCode == 200) {
            ElMessage.success('保存成功')
            dialogFormVisible9.value = false
        }
        else {
            ElMessage.error('保存失败')
        }
    })
}
const formpEnterprise = reactive({
    goodsId: 1,
    firmName: "",
    licenseNumber: "",
    ePhoto: ""
})
const getPEnterprise = () => {
    axios.get('https://localhost:44301/api/Processingr/GetPEnterprise', {
        params: {
            id: formpEnterprise.goodsId
        }
    }).then(res => {

        formpEnterprise.firmName = res.data.data.firmName
        formpEnterprise.licenseNumber = res.data.data.licenseNumber
        formpEnterprise.ePhoto = res.data.data.ePhoto
    })
}
//#endregion




//就绪函数
onMounted(() => {
    GetTraceabilities()
    getCultivation()
    getEnterprise()
    getSlaughter()
    getProcessingr()
    getRawMaterial()
    getAccessories()
    getAdditive()
    getPackaging()
    getPEnterprise()
    GetPrivinces()
    getSEnterprises()
})

</script>
<style scoped>
.avatar-uploader .avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
}
</style>